package cn.tedu.boot052.controller;

import cn.tedu.boot052.entity.User;
import cn.tedu.boot052.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    UserMapper mapper;
    @RequestMapping("/reg2")
    public String reg2(@RequestBody User user){
        User u=mapper.select(user.getUsername());
        if (u!=null){
            return "用户已存在";
        }
        mapper.insert(user);
        return "注册成功";
    }
    @RequestMapping("/login2")
    public String login2(@RequestBody User user){
        User us=mapper.select(user.getUsername());
        if (us!=null){
            if (user.getPassword().equals(us.getPassword())){
                return "登陆成功";
            }
            return "密码错误";
        }
        return "用户不存在";
    }
}
